package com.cn.demo4.service.impl;

import com.cn.demo4.dao.ProductDao;
import com.cn.demo4.dao.impl.ProductDaoImpl;
import com.cn.demo4.model.ProductModel;
import com.cn.demo4.service.IProductService;

import java.util.List;

public class ProductServiceImpl implements IProductService {
    @Override
    public List<ProductModel> findAll(ProductModel productModel) {
        ProductDao ProductDao = new ProductDaoImpl();
        return ProductDao.findAll(productModel);
    }

    @Override
    public String add(ProductModel productModel) {
        ProductDao ProductDao = new ProductDaoImpl();

        return ProductDao.add(productModel) == 1 ? "success" : "error";
    }

    @Override
    public int del(Integer id) {
        ProductDao productDao = new ProductDaoImpl();
        return productDao.del(id);
    }

    @Override
    public ProductModel findById(Integer id) {
        ProductDao productDao = new ProductDaoImpl();
        return productDao.findById(id);
    }

    @Override
    public String update(ProductModel productModel) {
        ProductDao productDao = new ProductDaoImpl();
        return productDao.update(productModel) == 1 ? "success" : "error";
    }

    @Override
    public int getCount(ProductModel productModel) {
        ProductDao productDao = new ProductDaoImpl();
        return productDao.getCount(productModel);
    }

    @Override
    public List<ProductModel> getProductModelListForHome() {
        ProductDao ProductDao = new ProductDaoImpl();
        return ProductDao.getProductModelListForHome();
    }


}
